<!--
  -    Copyright (c) 2018-2025, infomng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: infomng
  -->
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page.sync="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="handleDel">
        <template slot="menuLeft">
        <!--  <el-button
            v-if="permissions.pfoc_realityproductline_export"
            class="filter-item"
            plain
            type="primary"
            size="small"
            icon="el-icon-download"
            @click="exportExcel">导出
          </el-button>-->
          <el-button type="primary" icon="el-icon-plus" @click="addRealityLine">新增产线</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text"  icon="el-icon-view"  size="small" plain  @click="handleView(scope.row,scope.index)">预览</el-button>
          <el-button type="text"  icon="el-icon-edit"  size="small" plain  @click="editRealityLine(scope.row)">编辑</el-button>
<!--          <el-button type="text"  icon="el-icon-copy-document"  size="small" plain  @click="copyRealityLine(scope.row)">复制</el-button>-->
          <el-button type="text"  icon="el-icon-delete"  size="small" plain  @click="handleDel(scope.row,scope.index)">删除</el-button>
        </template>
      </avue-crud>
      <!--新增弹窗页面-->
      <el-dialog title=""
                 :visible.sync="addDialogVisible"
                 width="50%"
                 lock-scroll
                 v-if="addDialogVisible"
                 :close-on-click-modal="false"
                 :fullscreen="addDialogFull">
        <template slot="title">
          <div class="avue-crud__dialog__header">
                            <span class="el-dialog__title">
                                <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                                新增产线
                            </span>
            <!--  <div class="avue-crud__dialog__menu" style="margin-top: -7px;margin-right: 10px;" @click="planDetailsDialogFull? planDetailsDialogFull=false: planDetailsDialogFull=true">
                <i class="el-icon-full-screen"></i>
              </div>-->
          </div>
        </template>
        <!--新增实际产线页面-->
        <addRealityLine ref="addRealityRef" @closeAddReality="closeAddReality" :productLineTypeList="productLineTypeList"/>
      </el-dialog>

      <!--修改弹窗页面-->
      <el-dialog title=""
                 :visible.sync="editDialogVisible"
                 width="50%"
                 lock-scroll
                 v-if="editDialogVisible"
                 :fullscreen="editDialogFull">
        <el-backtop target=".el-card__body .el-dialog__wrapper .el-dialog" :right="15" :bottom="20" :visibility-height="1" />
        <el-backtop :bottom="60"></el-backtop>
        <template slot="title">
          <div class="avue-crud__dialog__header">
                            <span class="el-dialog__title">
                                <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                                修改产线
                            </span>
            <!--  <div class="avue-crud__dialog__menu" style="margin-top: -7px;margin-right: 10px;" @click="planDetailsDialogFull? planDetailsDialogFull=false: planDetailsDialogFull=true">
                <i class="el-icon-full-screen"></i>
              </div>-->
          </div>
        </template>
    <!--    <div class="pull-auto"  style="text-align: left;margin-left: 40px;font-size: 16px;color:#3478f5">
          <div class="block">
            品号：{{articleNumber}} <i class="el-breadcrumb__separator el-icon-arrow-right"></i>实际产线名称：{{realityLineName}}<i class="el-breadcrumb__separator el-icon-arrow-right"></i>组织：{{organizationName}}<i class="el-breadcrumb__separator el-icon-arrow-right"></i>工艺产线名称：{{craftLineName}}
          </div>
          <div class="block">

          </div>
        </div>-->
        <!--修改实际产线页面-->
        <editRealityLine ref="editRealityRef" @closeEditReality="closeEditReality" :lineId="id" :productLineTypeList="productLineTypeList" :workshopSectionList="workshopSectionList"/>
      </el-dialog>


      <!--预览弹窗页面-->
      <el-dialog title=""
                 :visible.sync="viewDialogVisible"
                 width="50%"
                 lock-scroll
                 v-if="viewDialogVisible"
                 :fullscreen="viewDialogFull">
        <el-backtop target=".el-card__body .el-dialog__wrapper .el-dialog" :right="15" :bottom="20" :visibility-height="1" />
        <el-backtop :bottom="60"></el-backtop>
        <template slot="title">
          <div class="avue-crud__dialog__header">
            <span class="el-dialog__title">
                <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                产线预览
            </span>
          </div>
        </template>
        <!--预览实际产线页面-->
        <viewRealityLine ref="viewRealityRef"  :lineId="id" :productLineTypeList="productLineTypeList"   :workshopSectionList="workshopSectionList"/>
      </el-dialog>

      <!--复制页面-->
      <el-dialog title="复制产线"
                 v-loading="copyLoading"
                 element-loading-text="复制产线中，请稍等..."
                 :visible.sync="copyDialogVisible"
                 width="40%"
                 :close-on-click-modal=false
                 v-if="copyDialogVisible"
                 lock-scroll>
        <div class="pull-auto"  style="text-align: left;margin-left: 10px;font-size: 14px;color:#3478f5">
          <div class="block">
            产线类型：{{productLineType}}<i class="el-breadcrumb__separator el-icon-arrow-right"></i>产线名称：{{realityLineName}}<i class="el-breadcrumb__separator el-icon-arrow-right"></i>产品工艺名称：{{productProcessName}}
          </div>
        </div>
        <div class="pull-auto"  style="text-align: center;">
          <div class="pull-auto"  style="text-align: center;width: 60%;padding:50px 0;display: inline-block;">
            <el-form label-position="right" label-width="100px">
              <el-form-item label="品号：">
                <el-input v-model="articleNumber"></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div class="pull-auto"  style="text-align: center;margin-top:20px;">
            <el-button size="small"  type="primary" @click="copyOk">确 定</el-button>
            <el-button size="small"  @click="copyCancel">取 消</el-button>
          </div>
        </div>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import { fetchList, addObj, putObj, delObj,copyLine} from '@/api/pfoc/realityproductline'
import { tableOption } from '@/const/crud/pfoc/realityproductline'
import { remote} from '@/api/admin/dict'
import { mapGetters } from 'vuex'
/**引入新增实际产线页面*/
import addRealityLine from '@/views/pfoc/realityproductline/add-reality-line'
/**引入修改实际产线页面*/
import editRealityLine from '@/views/pfoc/realityproductline/edit-reality-line'
/**引入预览实际产线页面*/
import viewRealityLine from '@/views/pfoc/realityproductline/view-reality-line'
/**
 * 实际产线管理
 */
export default {
    name: 'realityproductline',
    components: {
        //新增实际产线页面
        addRealityLine,
        //修改实际产线页面
        editRealityLine,
        //预览实际产线页面
        viewRealityLine,
    },
    data() {
      return {
        searchForm: {},
        tableData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
        },
        tableLoading: false,
        tableOption: tableOption,
        addDialogVisible:false,//新增实际产线页面开关
        addDialogFull:false,//新增实际产线页面弹窗缩放开关（默认放大）
        editDialogVisible:false,//修改实际产线页面开关
        editDialogFull:true,//修改实际产线页面弹窗缩放开关（默认放大）
        viewDialogVisible:false,//预览实际产线页面开关
        viewDialogFull:true,//预览实际产线页面弹窗缩放开关（默认放大）
        articleNumber:null,//品号
        craftLineName:null,//工艺产线名称
        organizationName:null,//组织名称
        realityLineName:null,//实际产线名称
        id:null,//实际产线ID（主表数据ID),
        copyLoading:false,//复制加载遮罩
        copyDialogVisible:false,//复制填充开关
        productLineTypeList:[],//产品类型集合
        productLineType:null,//产品类型
        workshopSectionList:[],//工段集合
        productProcessName:null,//产品工艺

      }
    },
    computed: {
      ...mapGetters(['permissions']),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permissions.pfoc_realityproductline_add, false),
          delBtn: this.vaildData(this.permissions.pfoc_realityproductline_del, false),
          editBtn: this.vaildData(this.permissions.pfoc_realityproductline_edit, false)
        }
      }
    },
    mounted() {
        //获取产线类型
        this.getProductLineTypeListData();
        //获取工段
        this.getWorkshopSectionListData();

    },
    methods: {
      // 列表查询
      getList(page, params) {
        this.tableLoading = true
        fetchList(Object.assign({
          descs:"create_time",
          current: page.currentPage,
          size: page.pageSize
        }, params, this.searchForm)).then(response => {
          this.tableData = response.data.data.records
          this.page.total = response.data.data.total
          this.tableLoading = false
        }).catch(() => {
          this.tableLoading = false
        })
      },
      // 删除
      handleDel: function(row, index) {
        this.$confirm('是否确认删除ID为' + row.id, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return delObj(row.id)
        }).then(data => {
          this.$message.success('删除成功')
          this.getList(this.page)
        })
      },
      // 更新
      handleUpdate: function(row, index, done, loading) {
        putObj(row).then(data => {
          this.$message.success('修改成功')
          done()
          this.getList(this.page)
        }).catch(() => {
          loading()
        })
      },
      // 保存
      handleSave: function(row, done, loading) {
        addObj(row).then(data => {
          this.$message.success('添加成功')
          done()
          this.getList(this.page)
        }).catch(() => {
          loading()
        })
      },
      // 每页条数改变事件
      sizeChange(pageSize) {
        this.page.pageSize = pageSize
      },
      // 当前页发生改变事件
      currentChange(current) {
        this.page.currentPage = current
      },
      // 查询事件
      searchChange(form, done) {
        this.searchForm = form
        this.page.currentPage = 1
        this.getList(this.page, form)
        done()
      },
      // 刷新事件
      refreshChange() {
        this.getList(this.page)
      },
      //  导出excel
      exportExcel() {
        this.downBlobFile('/pfoc/realityproductline/export', this.searchForm, 'realityproductline.xlsx')
      },
      //新增实际产线
      addRealityLine(){
          //打开新增实际产线页面
          this.addDialogVisible = true;
      },
      //关闭新增实际产线弹窗
      closeAddReality(){
          //关闭新增实际产线页面
          this.addDialogVisible = false;
          //刷新列表
          this.refreshChange();
      },
      //修改工艺产线
      editRealityLine(row){
          this.articleNumber=row.articleNumber;//品号
          this.productProcessName=row.$productProcessName;//工艺产线名称
          this.productLineType =row.productLineType;//产线类型
          this.realityLineName = row.realityLineName;//实际产线名称
          this.organizationName = row.organizationName;//组织名称
          this.id = row.id;//实际产线ID用于修改时查询数据
          //打开修改实际产线页面
          this.editDialogVisible = true;
          this.$nextTick(() => {
              //调用修改页面实际产线查询方法
              this.$refs.editRealityRef.getRealityProductLineDetails();
          })
      },
      //关闭修改实际产线弹窗
      closeEditReality(){
          //关闭新增实际产线页面
          // this.editDialogVisible = false;
          //刷新列表
          this.refreshChange();
      },
      //预览
      handleView(row){
          this.articleNumber=row.articleNumber;//品号
          this.craftLineName=row.craftLineName;//工艺产线名称
          this.realityLineName = row.realityLineName;//实际产线名称
          this.productLineType =row.productLineType;//产线类型
          this.organizationName = row.organizationName;//组织名称
          this.id = row.id;//实际产线ID用于预览时查询数据
          //打开预览实际产线页面
          this.viewDialogVisible = true;
          this.$nextTick(() => {
              //调用预览页面实际产线查询方法
              this.$refs.viewRealityRef.getRealityProductLineDetails();
          })
      },
      //复制
      copyRealityLine(row){
          this.craftLineName=row.craftLineName;//工艺产线名称
          this.realityLineName = row.realityLineName;//实际产线名称
          this.organizationName = row.organizationName;//组织名称
          this.productLineType =row.productLineType;//产线类型
          this.id = row.id;//实际产线ID
          //打开复制弹窗
          this.copyDialogVisible = true;
      },
      //复制确认
      copyOk(){
          if(this.validatenull(this.articleNumber)){
              this.$message.warning("请输入品号");
              return;
          }
           this.copyLoading = true;//开启加载遮罩
           const params = {
               id:this.id, //产线ID
               articleNumber:this.articleNumber //品号
           }
           copyLine(params).then(data => {
              this.$message.success('复制成功')
              this.refreshChange();
              this.copyCancel();//关闭
          }).catch(() => {
               this.copyLoading=false
          })
      },
      //复制取消
      copyCancel(){
          this.articleNumber=null; //品号
          this.craftLineName=null;//工艺产线名称
          this.realityLineName = null;//实际产线名称
          this.organizationName = null;//组织名称
          this.id = null;//实际产线ID
          //关闭复制弹窗
          this.copyDialogVisible = false;
          this.copyLoading=false
      },
      //获取产线类型
      getProductLineTypeListData(){
          remote("product_line").then(response => {
              this.productLineTypeList=response.data.data;
          })

      },
      //获取工段
      getWorkshopSectionListData(){
          remote("workshop_section").then(response => {
              this.workshopSectionList=response.data.data;
          })
      }
  }
}
</script>
